<?php
sleep(1);
require_once("../inc/connect.php");
require_once("../inc/genfunction.php");

$select_start = $_POST['date_start'];
$select_end = $_POST['date_end'];
$numTables = countTable();

echo "<table id='statusTable'>";
$check = 1;

for($i=1;$i<=$numTables;$i++) {

	if($check%8 == 1) {
		echo "<tr>";
	}
	
	$sql = "SELECT * FROM table$i WHERE ('$select_start'>=date_start  AND '$select_start'<=date_end) OR ('$select_end'>=date_start  AND '$select_end'<=date_end);";
	$result = mysql_query($sql);

	if(mysql_num_rows($result) > 0 ) {
		echo "<td style='background-color:#EEEEE0'><img src='pic/false.png'>";
		echo "<br><span id='numTable_false' ><br><font color='red'>โต๊ะที่ $i (ไม่ว่าง)</font></span></td>";
	}else {
		echo "<td id='table_$i' name='nameTable' onMouseOver='overObject($i)' onMouseOut='outObject($i)'><a href='#'class='poplight' onclick='registerPopup($i)'><img src='pic/true.png'><br>";
		echo "<span id='numTable_true'><br><font color='#FF4500'>โต๊ะที่ $i</font></span></a></td>";
	}

	if( $check%8==0 ) {
		echo  "</tr>";
		$check = 0;
	}
	$check++;
}

echo "</table>";

?>
